package com.ymatou.iapi.csim.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.GetUserSessionStatusBean;
import com.ymatou.iapi.csim.parameter.SendMessageBean;
import com.ymatou.iapi.csim.parameter.SendMessageCSBean;
import com.ymatou.iapi.csim.service.GetUserSessionStatusCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_cssession;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_queuesessionWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
/**
*获取用户是否在会话中
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserSessionStatus{
	private static GetUserSessionStatusBean bean;
	private static GetUserSessionStatusCall call;
	private CsimCallService service=new CsimCallService();
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private static Integer userId=Integer.parseInt(EnvSetup.getData("userId_IM").toString());
	private static ymt_cssessionWapper csSessionWapper=new ymt_cssessionWapper();
	private static ymt_onlinecsWapper onlinecsWapper=new ymt_onlinecsWapper();
	private static ymt_queuesessionWapper queuesessionWapper=new ymt_queuesessionWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取用户是否在会话中");
	}

	@Before
	public void caseUp() {
		bean=new GetUserSessionStatusBean();
		call=new GetUserSessionStatusCall();
		Logger.comment("删除旧数据");
		onlinecsWapper.deleteBy(MapUtil.hashMap("csId",csId,"Status",0));
		csSessionWapper.deleteByUserId(MapUtil.hashMap("UserId",userId,"Status",0));
		queuesessionWapper.deleteAll();
		
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserSessionStatus_1() {
		Logger.start(true,"获取用户是否在会话中，验证在会话中");
		try {
			//客服上线
			service.getOnlineCS(csId);
			//打开会话
			ymt_cssession cssession=service.getOpenSession(csId,userId);
			//发消息
			SendMessageCSBean sendMessageCSBean=service.setSendMessageCSBean();
			sendMessageCSBean.setSessionId(cssession.getId());
			sendMessageCSBean.setCsId(csId);
			sendMessageCSBean.setUserId(userId);
			service.setSendMessageCSCall(sendMessageCSBean);
			
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
			Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
			Logger.verifyEquals(false, call.getResult().get("InSession"), "验证InSession,是否在会话或者会话队列中 ");
			Logger.verifyEquals("200", call.getStatus(), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserSessionStatus_2() {
		Logger.start(true,"获取用户是否在会话中，验证存在队列表中");
		try {
			//发消息
			SendMessageBean sendMessageBean=service.setSendMessageBean();
			sendMessageBean.setUserId(userId);
			service.setSendMessageCall(sendMessageBean);
			
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
			Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
			Logger.verifyEquals(true, call.getResult().get("InSession"), "验证InSession,是否在会话或者会话队列中 ");
			Logger.verifyEquals("200", call.getStatus(), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserSessionStatus_3() {
		Logger.start(true,"获取用户是否在会话中，验证不在会话中");
		try {
			
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
			Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
			Logger.verifyEquals(false, call.getResult().get("InSession"), "验证InSession,是否在会话或者会话队列中 ");
			Logger.verifyEquals("200", call.getStatus(), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}